#  Name:		weather_noaa
#  Version:		0.1
#  Part Of:		linuxrules
#  Modified:	Sun Nov 21 2010, 20:11:17
#  TUTORIAL

#  See COPYING for linuxrules GPL3 licensing info.

BEGIN {
# For usage with noaa weather service
#  http://weather.noaa.gov/pub/data/observations/metar/decoded/STATION_CODE.TXT
# Save it recurrently (remind,cron,at) as log in your home and you are done.
# DATA MODEL IS THIS:
# Bogota / Eldorado, Colombia (SKBO) 04-43N 074-09W 2548M
# Nov 20, 2010 - 09:00 PM EST / 2010.11.21 0200 UTC
# Wind: Variable at 2 MPH (2 KT):0
# Visibility: greater than 7 mile(s):0
# Sky conditions: mostly cloudy
# Temperature: 53 F (12 C)
# Dew Point: 51 F (11 C)
# Relative Humidity: 93%
# Pressure (altimeter): 30.31 in. Hg (1026 hPa)
# ob: SKBO 210200Z VRB02KT 9999 FEW017 BKN080 12/11 A3031 NOSIG
# cycle: 2

    home = ENVIRON["HOME"] 
    FS="[ |(|)]"
    NR = 0

	while ((getline < (home "/.local/cache/weather/log")) > 0) {
        NR++

        if (NR < 2)
            _weather["NOAA_CITY"] = $1

        if ($0 ~ /Visibility:/)
            _weather["NOAA_VISIBILITY"] = "'" $7 "'"

        if ($0 ~ /Sky conditions:/)
        {
            if ($5)
                _weather["NOAA_SKY"] = "'" $3 " " $4 " " $5 "'"
            else
                if ($4)
                    _weather["NOAA_SKY"] = "'" $3 " " $4 "'"
                else
                    _weather["NOAA_SKY"] = $3

             _weather["NOAA_SKY2"] = _weather["NOAA_SKY"]

             sub(/mostly/, "+", _weather["NOAA_SKY2"])
             sub(/partly/, "~", _weather["NOAA_SKY2"])
        }
        
        if ($0 ~ /Temperature:/)
        {
            _weather["NOAA_TEMP_C"] = $5
            _weather["NOAA_TEMP_F"] = $2
        }

        if ($0 ~ /Dew Point:/)
        {
            _weather["NOAA_DEWPOINT_C"] = $6
            _weather["NOAA_DEWPOINT_F"] = $3
        }

        if ($0 ~ /Relative Humidity:/)
            _weather["NOAA_HUMIDITY"] = $3

        if ($0 ~ /Pressure \(altimeter\):/)
            _weather["NOAA_PRESSURE"] = "'" $9 " " $10 "'"
    }

    FS=" "
	close(home "/.local/cache/weather/log")
}

# vim:ft=awk:
